﻿using System;
using System.Windows.Forms;
using EasyBackup.Utils;

namespace EasyBackup.Forms
{
    public partial class AppForm : Form
    {                
        public AppForm()
        {            
            InitializeComponent();                                                    
        }        

        private void AppFormLoad(object sender, EventArgs e)
        {
            InitForm();
            Log.CheckDir();
            Log.Clear();
            Schedule.CheckFile();            
            Schedule.Get();
            AppTimer.Init(timer);            
        }

        private void InitForm()
        {
            notifyIcon.Visible = true;
            Hide();

            appDirTextBox.Text = App.Location;
            logDirTextBox.Text = App.LogDir;
            scheduleTextBox.Text = App.SchedulePath;
        }

        private void HideOrShowForm()
        {
            if (Visible)
            {
                Hide();
            }
            else
            {
                Show();
                WindowState = FormWindowState.Normal;
                CenterToScreen();
            }
        }
              
        private void ExitMenuItemClick(object sender, EventArgs e)
        {
            Application.Exit();
        }        

        private void SettingsMenuItemClick(object sender, EventArgs e)
        {
            HideOrShowForm();
        }        

        private void NotifyIconMouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                HideOrShowForm();
            }            
        }        

        private void AppFormFormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                HideOrShowForm();
            }              
        }

        private void AppLabelClick(object sender, EventArgs e)
        {
            Explorer.Open(App.Location);            
        }

        private void LogLabelClick(object sender, EventArgs e)
        {
            Explorer.Open(App.LogDir);            
        }

        private void ScheduleLabelClick(object sender, EventArgs e)
        {
            Explorer.Open(App.SchedulePath);            
        }

        private void RestartAppClick(object sender, EventArgs e)
        {            
            Application.Restart();
        }                       
    }
}
